var dd_math = {

	// absolute
	abs: function(val) {return Math.abs(val);},

	// power
	pow: function(num, power) {return Math.pow(num, power);},

	/* calculate catmull-rom curve value (1D)
	 * returns the calculated value
	 */
	catmullrom: function(t, p0, p1, p2, p3) {
		return 0.5 *(
			(2 *p1) +
			(-p0 +p2) *t +
			(2*p0 -5*p1 +4*p2 -p3) *dd_math.pow(t, 2) +
			(-p0 +3*p1 -3*p2 +p3) *dd_math.pow(t, 3)
		);
	},

	/* calculate catmull-rom curve value (2D)
	 * sets the calculated value in `point`
	 */
	catmullrom2d: function(point, t, p0, p1, p2, p3) {
		point.x = dd_math.catmullrom(t, p0.x, p1.x, p2.x, p3.x);
		point.y = dd_math.catmullrom(t, p0.y, p1.y, p2.y, p3.y);
	},

	// dot product
	dot: function(v1, v2) {
		return v1.x *v2.x +v1.y *v2.y;
	},

	sqrt: function(val) {
		return Math.sqrt(val);
	},

	// magnitude
	mag: function(v) { return dd_math.sqrt( dd_math.pow(v.x, 2) +dd_math.pow(v.y, 2)); },

	angle_between_vectors: function(v1, v2) {
		var dot = dd_math.dot(v1, v2);
		var mag1 = dd_math.mag(v1);
		var mag2 = dd_math.mag(v2);
		return Math.acos(dot /(mag1 *mag2));
	},

	/* returns a random integer from 0 (inclusive) to `val` (exclusive)
	 */
	rand: function(val) {
		return parseInt(Math.random() *val);
	},
};
